package com.hxzy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxzy.common.util.WaimaiThreadLocal;
import com.hxzy.entity.AddressBook;
import com.hxzy.mapper.AddressBookMapper;
import com.hxzy.service.AddressBookService;
import com.hxzy.vo.LoginVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 客户收货地址
 * @author Administrator
 */
@Service
public class AddressBookServiceImpl extends ServiceImpl<AddressBookMapper, AddressBook> implements AddressBookService {
    /**
     * 删除收货地址
     * @param id
     * @return
     */
    @Override
    public int delete(Long id) {
        return this.getBaseMapper().delete(id);
    }

    /**
     * 设定默认收货地址
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateDefault(Long id) {
        LoginVO loginVO= WaimaiThreadLocal.getCurrent();

        this.getBaseMapper().cancelDefaultAddress(loginVO.getAccountVO().getId());

        int  count=this.getBaseMapper().updateDefaultAddress(id);
        return count;
    }
}
